version 8.0 
log using presidentialfig.log, replace
 #delimit ;

*     ***************************************************************** *;
*     ***************************************************************** *;
*       File-Name:      presidentialfig.do                              *;
*       Date:           1/23/05                                         *;
*       Author:         MRG                                             *;
*       Purpose:        Do-file to create figures showing the marginal  *;
*                       effect of temporally-proximate presidential     *;
*                       elections as the number of candidates changes   *;
*                       for CPS paper.                                  *;
*       Input File:     legislative_new.dta                             *;
*       Output File:    presidentialfig.log                             *;
*       Data Output:    None                                            *;
*       Previous file:                                                  *;
*       Machine:        Office                                          *;
*     ****************************************************************  *;
*     ****************************************************************  *;

set mem 10m;
set matsize 150;

*     ****************************************************************  *;
*       First, get figures using Amorim Neto and Cox data               *;
*     ****************************************************************  *;


use h:\cps\coxappend.dta;

set obs 100;

replace upper=upper*100;

generate uppereneth=upper*eneth;

regress enpv proximit enpres proxpres eneth lnml lmleneth uppereneth upper if drop==0;

generate JH=((_n-1)/10);

replace JH=. if _n>60;

matrix b=e(b); 
matrix V=e(V); 
scalar b1=b[1,1]; 
scalar b2=b[1,2];
scalar b3=b[1,3];

scalar varb1=V[1,1]; 
scalar varb2=V[2,2]; 
scalar varb3=V[3,3];
scalar covb1b3=V[1,3]; 
scalar covb2b3=V[2,3];
set more off;

*     ****************************************************************  *;
*         Create full range of marginal effect                          *;
*     ****************************************************************  *;

gen conb=b1+b3*JH if _n<60;
set more off;

*     ****************************************************************  *;
*           Create full range of standard errors                        *;
*     ****************************************************************  *;

gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<60; 
set more off;

*     ****************************************************************  *;
*               Generate confidence intervals at the 90% level          *;
*     ****************************************************************  *;

gen a=1.684*conse; 
gen top=conb+a; 
gen bottom=conb-a;
set textsize 100;

graph twoway  line conb JH, clwidth(medium) clcolor(blue) clcolor(black)
        ||  line top  JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  line bottom JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  ,   
            xlabel(0 1 2 3 4 5 6, labsize(2.5)) 
            ylabel(-8 -6 -4 -2 0 2 4 6 8 10 , labsize(2.5))
            yscale(noline)
            xscale(noline)
            legend(col(1) order(1 2) label(1 "Marginal Effect of Temporally-Proximate Presidential Elections") label(2 "90% Confidence Interval") 
                  label(3 " "))
        yline(0, lcolor(black)) yline(-8 -6 -4 -2 2 4 6 8 10 , lcolor(white))  
            title("Marginal Effect of Temporally-Proximate Presidential Elections", size(4))
            subtitle(" " "Dependent Variable: Effective Number of Electoral Parties" " ", size(3))
            xtitle(Effective Number of Presidential Candidates, size(3)  )
        xsca(titlegap(2))
        ysca(titlegap(2))
            ytitle("Marginal Effect of Temporally-Proximate" "Presidential Elections", size(3))
        scheme(s2mono) graphregion(fcolor(white)); 
        
       
*graph export  h:\Dissertation\parties\cps\coxp.eps, replace;

*     ****************************************************************  *;
*       Conclusion:                                                     *;
*       At 90% significance: Temporally-proximate presidential elections*;
*       reduce the number of electoral parties when the number of       *;
*       presidential candidates is less than 2.5.  They have no effect  *;
*       when 2.4<presidential candidates<4.7. They have a positive      *;
*       effect when presidential candidates>4.7.                        *;
*       At 95% significance: Temporally-proximate presidential elections*;
*       reduce the number of electoral parties when the number of       *;
*       presidential candidates is less than 2.4.  They have not effect *;
*       when 2.4<presidential candidates<5.2. They have a positive      *;
*       effect when presidential candidates>5.2. To see this, change    *;
*       to 2.021.                                                       *;
*     ****************************************************************  *;


*     ****************************************************************  *;
*                       Now let us turn to our data                     *;
*     ****************************************************************  *;

clear;

use h:\cps\legislative_new.dta;

*     ****************************************************************  *;
*                    Relabel and Define Variables                       *;
*     ****************************************************************  *;

label var country  "countryname";
label var newdem "first election as new democracy";
label var countrynumber "countrynumber";
label var year "year";
label var regime "regime as of 31 December of given year 0=democracy 1=dictatorship";
label var regime_leg "regime type at time of legislative election 0 = democracy 1=dictatorship";
label var legelec "legislative election";
label var preselec "presidential election";
label var eighties "election in 1980s closest to 1985";
label var old "elections in countries that did not transition to democracy in 1990s";
label var nineties "elections in 1990s closest to 1995";
label var proximity1 "proximity - continuous";
label var proximity2 "proximity - dichotomous";
label var enpp "parliamentary parties - uncorrected";
label var enpp1 "parliamentary parties - corrected";
label var enep "electoral parties - uncorrected";
label var enep1 "electoral parties - corrected";
label var enpres "effective number of presidential candidates";
label var seats "assembly size";
label var districts "number of electoral districts";
label var avemag "average district magnitude";
label var medmag "median district magnitude";
label var upperseats "number of uppertier seats";
label var uppertier "percentage of uppertier seats";
label var eneg "effective number of ethnic groups  fearon";

describe;


*     ****************************************************************  *;
*       Would like to drop countries that have no recognizable parties  *;
*       since I am interested in determining the number of parties.     *;
*       Drop Kiribati, Marshall Islands, Micronesia, Nauru, Palau,      *;
*       Lebanon (at least no votes by party), Kyrgzstan.                *;
*       Since I am interested in competitive elections I drop the       *;
*       elections that occurred in Colombia between 1958 and 1970 due   *;
*       to a constitutional agreement to share power between the        *;
*       conservative and liberal parties.                               *;
*       Also drop the Congolese elections of 1963.  Although there were *;
*       multiple parties permitted, all candidates ran on a single list.*;
*       Thus, there was no actual competition in this election.         *;
*     ****************************************************************  *;

drop if countrynumber==163;
drop if countrynumber==165;
drop if countrynumber==197;
drop if countrynumber==189;
drop if countrynumber==146;
drop if countrynumber==198;
drop if countrynumber==167;
drop if countrynumber==70 & year==1958;
drop if countrynumber==70 & year==1960;
drop if countrynumber==70 & year==1962;
drop if countrynumber==70 & year==1964;
drop if countrynumber==70 & year==1966;
drop if countrynumber==70 & year==1968;
drop if countrynumber==70 & year==1970;
drop if countrynumber==12 & year==1963;

*     ****************************************************************  *;
*       Generate interaction variables ready for regressions.           *;
*     ****************************************************************  *;

generate logmag=ln(avemag);
generate uppertier_eneg = uppertier*eneg;
generate logmag_eneg = logmag*eneg;
generate proximity1_enpres = proximity1*enpres;

*     ****************************************************************  *;
*       Need to drop elections that use a fused vote in legislative     *;
*       and presidential elections.                                     *;
*       Drop Bolivia, Uruguay, Honduras up to and including the 1993    *;
*       elections, Guatemala elections in 1990 (fused vote with         *;
*       national district), Dominican Republic elections in 1966, 1970, *;
*       1974 and 1986.                                                  *;
*     ****************************************************************  *;

drop if countrynumber==67;
drop if countrynumber==76;
drop if countrynumber==59 & year==1957;
drop if countrynumber==59 & year==1971;
drop if countrynumber==59 & year==1985;
drop if countrynumber==59 & year==1989;
drop if countrynumber==59 & year==1993;
drop if countrynumber==57 & year==1990;
drop if countrynumber==54 & year==1966;
drop if countrynumber==54 & year==1970;
drop if countrynumber==54 & year==1974;
drop if countrynumber==54 & year==1986;

*     ****************************************************************  *;
*           Now drop countries with majoritarian uppertiers             *;
*     ****************************************************************  *;

drop if countrynumber==132;
drop if countrynumber==29;
drop if countrynumber==87 & year==1988;
drop if countrynumber==87 & year==1992;
drop if countrynumber==87 & year==1996;
drop if countrynumber==116 & year==1987;
drop if countrynumber==116 & year==1996;

*     ****************************************************************  *;
*       Drop those countries where enep1 others are greater than 15% of *;
*       the vote or seats.                                              *;
*     ****************************************************************  *;

drop if enep_others>15 & enep_others<100;

*     ****************************************************************  *;
*     ****************************************************************  *;
*     ****************************************************************  *;
*                      Figure for 1990s                                 *;
*     ****************************************************************  *;
*     ****************************************************************  *;
*     ****************************************************************  *;
 
regress enep1 proximity1 enpres proximity1_enpres eneg logmag logmag_eneg uppertier_eneg uppertier if nineties==1;

generate JH=((_n-1)/10);

replace JH=. if _n>60;

matrix b=e(b); 
matrix V=e(V); 
scalar b1=b[1,1]; 
scalar b2=b[1,2];
scalar b3=b[1,3];

scalar varb1=V[1,1]; 
scalar varb2=V[2,2]; 
scalar varb3=V[3,3];
scalar covb1b3=V[1,3]; 
scalar covb2b3=V[2,3];
set more off;

*     ****************************************************************  *;
*         Create full range of marginal effect                          *;
*     ****************************************************************  *;

gen conb=b1+b3*JH if _n<60;
set more off;

*     ****************************************************************  *;
*           Create full range of standard errors                        *;
*     ****************************************************************  *;

gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<60; 
set more off;

*     ****************************************************************  *;
*               Generate confidence intervals at the 90% level          *;
*     ****************************************************************  *;

gen a=1.676*conse; 
gen top=conb+a; 
gen bottom=conb-a;
set textsize 100;

graph twoway  line conb JH, clwidth(medium) clcolor(blue) clcolor(black)
        ||  line top  JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  line bottom JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  ,   
            xlabel(0 1 2 3 4 5 6, labsize(2.5)) 
            ylabel(-8 -6 -4 -2 0 2 4 6 8 10 , labsize(2.5))
            yscale(noline)
            xscale(noline)
            legend(col(1) order(1 2) label(1 "Marginal Effect of Temporally-Proximate Presidential Elections") label(2 "90% Confidence Interval") 
                  label(3 " "))
        yline(0, lcolor(black)) yline(-5 5 -10 -15, lcolor(white))  
            title("Marginal Effect of Temporally-Proximate Presidential Elections", size(4))
            subtitle(" " "Dependent Variable: Effective Number of Electoral Parties" " ", size(3))
            xtitle(Effective Number of Presidential Candidates, size(3)  )
        xsca(titlegap(2))
        ysca(titlegap(2))
            ytitle("Marginal Effect of Temporally-Proximate" "Presidential Elections", size(3))
        scheme(s2mono) graphregion(fcolor(white));        
       
*graph export  h:\Dissertation\parties\cps\nineties.eps, replace;

*     ****************************************************************  *;
*       Conclusion:                                                     *;
*       90% confidence: Temporally-proximate presidential elections     *;
*       reduce the number of electoral parties when the number of       *;
*       presidential candidates is less than 2.8.  They have no effect  *;
*       when presidential candidates are greater than this.             *;
*       95% confidence: Temporally-proximate presidential elections     *;
*       reduce the number of electoral parties when the number of       *;
*       presidential candidates is less than 2.5.  They have no effect  *;
*       when presidential candidates are greater than this. To get this *;
*       change to 2.01.                                                 *;
*     ****************************************************************  *;

drop JH conb conse a top bottom;

*     ****************************************************************  *;
*     ****************************************************************  *;
*     ****************************************************************  *;
*                 Figure for 1990s - established democracies            *;
*     ****************************************************************  *;
*     ****************************************************************  *;
*     ****************************************************************  *;
 
regress enep1 proximity1 enpres proximity1_enpres eneg logmag logmag_eneg uppertier_eneg uppertier if nineties==1 & old==1;

generate JH=((_n-1)/10);

replace JH=. if _n>60;

matrix b=e(b); 
matrix V=e(V); 
scalar b1=b[1,1]; 
scalar b2=b[1,2];
scalar b3=b[1,3];

scalar varb1=V[1,1]; 
scalar varb2=V[2,2]; 
scalar varb3=V[3,3];
scalar covb1b3=V[1,3]; 
scalar covb2b3=V[2,3];
set more off;

*     ****************************************************************  *;
*         Create full range of marginal effect                          *;
*     ****************************************************************  *;

gen conb=b1+b3*JH if _n<60;
set more off;

*     ****************************************************************  *;
*           Create full range of standard errors                        *;
*     ****************************************************************  *;

gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<60; 
set more off;

*     ****************************************************************  *;
*               Generate confidence intervals at the 90% level          *;
*     ****************************************************************  *;

gen a=1.697*conse; 
gen top=conb+a; 
gen bottom=conb-a;
set textsize 100;

graph twoway  line conb JH, clwidth(medium) clcolor(blue) clcolor(black)
        ||  line top  JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  line bottom JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  ,   
            xlabel(0 1 2 3 4 5 6, labsize(2.5)) 
            ylabel(-8 -6 -4 -2 0 2 4 6 8 , labsize(2.5))
            yscale(noline)
            xscale(noline)
            legend(col(1) order(1 2) label(1 "Marginal Effect of Temporally-Proximate Presidential Elections") label(2 "90% Confidence Interval") 
                  label(3 " "))
        yline(0, lcolor(black)) yline(-8 -6 -4 -2 2 4 6 8, lcolor(white))  
            title("Marginal Effect of Temporally-Proximate Presidential Elections", size(4))
            subtitle(" " "Dependent Variable: Effective Number of Electoral Parties" " ", size(3))
            xtitle(Effective Number of Presidential Candidates, size(3)  )
        xsca(titlegap(2))
        ysca(titlegap(2))
            ytitle("Marginal Effect of Temporally-Proximate" "Presidential Elections", size(3))
        scheme(s2mono) graphregion(fcolor(white));       
       
*graph export  h:\Dissertation\parties\cps\nineties_established.eps, replace;

*     ****************************************************************  *;
*       Conclusion:                                                     *;
*       At 90% significance we have:                                    *;
*       Temporally-proximate presidential elections reduce the number   *;
*       of electoral parties when the number of presidential candidates *;
*       is less than 2.6.  They have not effect when                    *;
*       2.6<presidential candidates<5.3. They have a positive effect    *;
*       when presidential candidates>5.3. 
*       At 95% significance we have:                                    *;
*       Temporally-proximate presidential elections reduce the number   *;
*       of electoral parties when the number of presidential candidates *;
*       is less than 2.4.  They have no effect when presidential        *;
*       candidates are greater than this.  To get these results change  *;
*       `gen a=1.697*conse' to `gen a=2.042*conse`                      *;     ;                         
*     ****************************************************************  *;

drop JH conb conse a top bottom;

*     ****************************************************************  *;
*       Pooled Analysis - Whole Sample                                  *;
*     ****************************************************************  *;

regress enep1 proximity1 enpres  proximity1_enpres eneg logmag logmag_eneg  uppertier uppertier_eneg, robust cluster(country);

generate JH=((_n-1)/10);

replace JH=. if _n>60;

matrix b=e(b); 
matrix V=e(V); 
scalar b1=b[1,1]; 
scalar b2=b[1,2];
scalar b3=b[1,3];

scalar varb1=V[1,1]; 
scalar varb2=V[2,2]; 
scalar varb3=V[3,3];
scalar covb1b3=V[1,3]; 
scalar covb2b3=V[2,3];
set more off;

*     ****************************************************************  *;
*         Create full range of marginal effect                          *;
*     ****************************************************************  *;

gen conb=b1+b3*JH if _n<60;
set more off;

*     ****************************************************************  *;
*           Create full range of standard errors                        *;
*     ****************************************************************  *;

gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<60; 
set more off;

*     ****************************************************************  *;
*               Generate confidence intervals at the 90% level          *;
*     ****************************************************************  *;

gen a=1.645*conse; 
gen top=conb+a; 
gen bottom=conb-a;
set textsize 100;

graph twoway  line conb JH, clwidth(medium) clcolor(blue) clcolor(black)
        ||  line top  JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  line bottom JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  ,   
            xlabel(0 1 2 3 4 5 6, labsize(2.5)) 
            ylabel(-6 -4 -2 0 2 4 6 , labsize(2.5))
            yscale(noline)
            xscale(noline)
            legend(col(1) order(1 2) label(1 "Marginal Effect of Temporally-Proximate Presidential Elections") label(2 "90% Confidence Interval") 
                  label(3 " "))
        yline(0, lcolor(black)) yline(-6 -4 -2  2 4 6 , lcolor(white))  
            title("Marginal Effect of Temporally-Proximate Presidential Elections", size(4))
            subtitle(" " "Dependent Variable: Effective Number of Electoral Parties" " ", size(3))
            xtitle(Effective Number of Presidential Candidates, size(3)  )
        xsca(titlegap(2))
        ysca(titlegap(2))
            ytitle("Marginal Effect of Temporally-Proximate" "Presidential Elections", size(3))
        scheme(s2mono) graphregion(fcolor(white));        
             
*graph export  h:\Dissertation\parties\cps\pooled.eps, replace;

*     ****************************************************************  *;
*       Conclusion:                                                     *;
*       At 90% significance we have:                                    *;
*       Temporally-proximate presidential elections reduce the number   *;
*       of electoral parties when the number of presidential candidates *;
*       is less than 3.3.  They have no effect when presidential        *;
*       candidates are greater than this.                               *; 
*       At 95% significance we have:                                    *;
*       Temporally-proximate presidential elections reduce the number   *;
*       of electoral parties when the number of presidential candidates *;
*       is less than 3.1.  They have no effect when presidential        *;
*       candidates are greater than this.  To get this, change to 1.96  *;                         
*     ****************************************************************  *;


drop JH conb conse a top bottom;


*     ****************************************************************  *;
*       Pooled Analysis - Established Democracies                       *;
*     ****************************************************************  *;

regress enep1 proximity1 enpres  proximity1_enpres eneg logmag logmag_eneg  uppertier uppertier_eneg if old==1, robust cluster(country);

generate JH=((_n-1)/10);

replace JH=. if _n>60;

matrix b=e(b); 
matrix V=e(V); 
scalar b1=b[1,1]; 
scalar b2=b[1,2];
scalar b3=b[1,3];

scalar varb1=V[1,1]; 
scalar varb2=V[2,2]; 
scalar varb3=V[3,3];
scalar covb1b3=V[1,3]; 
scalar covb2b3=V[2,3];
set more off;

*     ****************************************************************  *;
*         Create full range of marginal effect                          *;
*     ****************************************************************  *;

gen conb=b1+b3*JH if _n<60;
set more off;

*     ****************************************************************  *;
*           Create full range of standard errors                        *;
*     ****************************************************************  *;

gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<60; 
set more off;

*     ****************************************************************  *;
*               Generate confidence intervals at the 90% level          *;
*     ****************************************************************  *;

gen a=1.645*conse; 
gen top=conb+a; 
gen bottom=conb-a;
set textsize 100;

graph twoway  line conb JH, clwidth(medium) clcolor(blue) clcolor(black)
        ||  line top  JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  line bottom JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  ,   
            xlabel(0 1 2 3 4 5 6, labsize(2.5)) 
            ylabel(-6 -4 -2 0 2 4  , labsize(2.5))
            yscale(noline)
            xscale(noline)
            legend(col(1) order(1 2) label(1 "Marginal Effect of Temporally-Proximate Presidential Elections") label(2 "90% Confidence Interval") 
                  label(3 " "))
        yline(0, lcolor(black)) yline(-6 -4 -2  2 4  , lcolor(white))  
            title("Marginal Effect of Temporally-Proximate Presidential Elections", size(4))
            subtitle(" " "Dependent Variable: Effective Number of Electoral Parties" " ", size(3))
            xtitle(Effective Number of Presidential Candidates, size(3)  )
        xsca(titlegap(2))
        ysca(titlegap(2))
            ytitle("Marginal Effect of Temporally-Proximate" "Presidential Elections", size(3))
        scheme(s2mono) graphregion(fcolor(white)); 
        
*graph export  h:\Dissertation\parties\cps\pooled_established.eps, replace;

*     ****************************************************************  *;
*       Conclusion:                                                     *;
*       At 90% significance we have:                                    *;
*       Temporally-proximate presidential elections reduce the number   *;
*       of electoral parties when the number of presidential candidates *;
*       is less than 3.3.  They have no effect when presidential        *;
*       candidates are greater than this.                               *;
*       Temporally-proximate presidential elections reduce the number   *;
*       of electoral parties when the number of presidential candidates *;
*       is less than 3.2.  They have no effect when presidential        *;
*       candidates are greater than this.  To get this, change to 1.96  *;                         
*     ****************************************************************  *;

drop JH conb conse a top bottom;

*     ****************************************************************  *;
*     ****************************************************************  *;
*       What if I now use XTPCSE?                                       *;
*     ****************************************************************  *;
*     ****************************************************************  *;

replace year=. if twoelections1==1;

tsset countrynumber year, yearly;

*     ****************************************************************  *;
*       xtpcse - no lagged dependent variable                           *;
*     ****************************************************************  *;

xtpcse enep1 proximity1 enpres  proximity1_enpres eneg logmag logmag_eneg  uppertier uppertier_eneg, pairwise;

generate JH=((_n-1)/10);

replace JH=. if _n>60;

matrix b=e(b); 
matrix V=e(V); 
scalar b1=b[1,1]; 
scalar b2=b[1,2];
scalar b3=b[1,3];

scalar varb1=V[1,1]; 
scalar varb2=V[2,2]; 
scalar varb3=V[3,3];
scalar covb1b3=V[1,3]; 
scalar covb2b3=V[2,3];
set more off;

*     ****************************************************************  *;
*         Create full range of marginal effect                          *;
*     ****************************************************************  *;

gen conb=b1+b3*JH if _n<60;
set more off;

*     ****************************************************************  *;
*           Create full range of standard errors                        *;
*     ****************************************************************  *;

gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<60; 
set more off;

*     ****************************************************************  *;
*               Generate confidence intervals at the 95% level          *;
*     ****************************************************************  *;

gen a=1.96*conse; 
gen top=conb+a; 
gen bottom=conb-a;
set textsize 100;

graph twoway  line conb JH, clwidth(medium) clcolor(blue) clcolor(black)
        ||  line top  JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  line bottom JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  ,   
            xlabel(0 1 2 3 4 5 6, labsize(2.5)) 
            ylabel(-6 -4 -2 0 2 4 6 8 10 , labsize(2.5))
            yscale(noline)
            xscale(noline)
            legend(col(1) order(1 2) label(1 "Marginal Effect of Temporally-Proximate Presidential Elections") label(2 "95% Confidence Interval") 
                  label(3 " "))
        yline(0, lcolor(black)) yline(-5 5 -10 -15, lcolor(white))  
            title("Marginal Effect of Temporally-Proximate Presidential Elections", size(4))
            subtitle(" " "Dependent Variable: Effective Number of Electoral Parties" " ", size(3))
            xtitle(Effective Number of Presidential Candidates, size(3)  )
        xsca(titlegap(2))
        ysca(titlegap(2))
            ytitle("Marginal Effect of Temporally-Proximate" "Presidential Elections", size(3))
        scheme(s2mono) graphregion(fcolor(white)); 
             
*graph export  h:\Dissertation\parties\cps\xtpcse_nolag.eps, replace;

*     ****************************************************************  *;
*       Conclusion:                                                     *;
*       At 95% significance we have:                                    *;
*       Temporally-proximate presidential elections reduce the number   *;
*       of electoral parties when the number of presidential candidates *;
*       is less than 3.4.  They have no effect when presidential        *;
*       candidates are greater than this.                               *;                         
*     ****************************************************************  *;

drop JH conb conse a top bottom;

*     ****************************************************************  *;
*       xtpcse - no lagged dependent variable, established democracies  *;
*     ****************************************************************  *;

xtpcse enep1 proximity1 enpres  proximity1_enpres eneg logmag logmag_eneg  uppertier uppertier_eneg if old==1, pairwise;

generate JH=((_n-1)/10);

replace JH=. if _n>60;

matrix b=e(b); 
matrix V=e(V); 
scalar b1=b[1,1]; 
scalar b2=b[1,2];
scalar b3=b[1,3];

scalar varb1=V[1,1]; 
scalar varb2=V[2,2]; 
scalar varb3=V[3,3];
scalar covb1b3=V[1,3]; 
scalar covb2b3=V[2,3];
set more off;

*     ****************************************************************  *;
*         Create full range of marginal effect                          *;
*     ****************************************************************  *;

gen conb=b1+b3*JH if _n<60;
set more off;

*     ****************************************************************  *;
*           Create full range of standard errors                        *;
*     ****************************************************************  *;

gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<60; 
set more off;

*     ****************************************************************  *;
*               Generate confidence intervals at the 95% level          *;
*     ****************************************************************  *;

gen a=1.96*conse; 
gen top=conb+a; 
gen bottom=conb-a;
set textsize 100;

graph twoway  line conb JH, clwidth(medium) clcolor(blue) clcolor(black)
        ||  line top  JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  line bottom JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  ,   
            xlabel(0 1 2 3 4 5 6, labsize(2.5)) 
            ylabel(-4 -3 -2 -1 0 1 2 3, labsize(2.5))
            yscale(noline)
            xscale(noline)
            legend(col(1) order(1 2) label(1 "Marginal Effect of Temporally-Proximate Presidential Elections") label(2 "95% Confidence Interval") 
                  label(3 " "))
        yline(0, lcolor(black)) yline(-5 5 -10 -15, lcolor(white))  
            title("Marginal Effect of Temporally-Proximate Presidential Elections", size(4))
            subtitle(" " "Dependent Variable: Effective Number of Electoral Parties" " ", size(3))
            xtitle(Effective Number of Presidential Candidates, size(3)  )
        xsca(titlegap(2))
        ysca(titlegap(2))
            ytitle("Marginal Effect of Temporally-Proximate" "Presidential Elections", size(3))
        scheme(s2mono) graphregion(fcolor(white));     
                  
*graph export  h:\Dissertation\parties\cps\presidential.eps, replace;

*     ****************************************************************  *;
*       Conclusion:                                                     *;
*       At 95% significance we have:                                    *;
*       Temporally-proximate presidential elections reduce the number   *;
*       of electoral parties when the number of presidential candidates *;
*       is less than 3.6.  They have no effect when presidential        *;
*       candidates are greater than 3.6.                                *;                         
*     ****************************************************************  *;

drop JH conb conse a top bottom;

*     ****************************************************************  *;
*               Generate lagged dependent variable                      *;
*     ****************************************************************  *;

sort country year;

by country: generate enep1_lag=enep1[_n-1];

replace enep1_lag = . if newdem==1;

*     ****************************************************************  *;
*       xtpcse - lagged dependent variable                              *;
*     ****************************************************************  *;

xtpcse enep1 proximity1 enpres  proximity1_enpres eneg logmag logmag_eneg enep1_lag uppertier uppertier_eneg, pairwise;

generate JH=((_n-1)/10);

replace JH=. if _n>60;

matrix b=e(b); 
matrix V=e(V); 
scalar b1=b[1,1]; 
scalar b2=b[1,2];
scalar b3=b[1,3];

scalar varb1=V[1,1]; 
scalar varb2=V[2,2]; 
scalar varb3=V[3,3];
scalar covb1b3=V[1,3]; 
scalar covb2b3=V[2,3];
set more off;

*     ****************************************************************  *;
*         Create full range of marginal effect                          *;
*     ****************************************************************  *;

gen conb=b1+b3*JH if _n<60;
set more off;

*     ****************************************************************  *;
*           Create full range of standard errors                        *;
*     ****************************************************************  *;

gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<60; 
set more off;

*     ****************************************************************  *;
*               Generate confidence intervals at the 95% level          *;
*     ****************************************************************  *;

gen a=1.96*conse; 
gen top=conb+a; 
gen bottom=conb-a;
set textsize 100;

graph twoway  line conb JH, clwidth(medium) clcolor(blue) clcolor(black)
        ||  line top  JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  line bottom JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  ,   
            xlabel(0 1 2 3 4 5 6, labsize(2.5)) 
            ylabel(-6 -4 -2 0 2 4 , labsize(2.5))
            yscale(noline)
            xscale(noline)
            legend(col(1) order(1 2) label(1 "Marginal Effect of Temporally-Proximate Presidential Elections") label(2 "95% Confidence Interval") 
                  label(3 " "))
        yline(0, lcolor(black)) yline(-5 5 -10 -15, lcolor(white))  
            title("Marginal Effect of Temporally-Proximate Presidential Elections", size(4))
            subtitle(" " "Dependent Variable: Effective Number of Electoral Parties" " ", size(3))
            xtitle(Effective Number of Presidential Candidates, size(3)  )
        xsca(titlegap(2))
        ysca(titlegap(2))
            ytitle("Marginal Effect of Temporally-Proximate" "Presidential Elections", size(3))
        scheme(s2mono) graphregion(fcolor(white)); 
                   
*graph export  h:\Dissertation\parties\cps\xtpcse_lag.eps, replace;

*     ****************************************************************  *;
*       Conclusion:                                                     *;
*       At 95% significance we have:                                    *;
*       Temporally-proximate presidential elections reduce the number   *;
*       of electoral parties when the number of presidential candidates *;
*       is between 0.1 and 2.4.  They have no effect when presidential  *;
*       candidates are greater than 2.4.                                *;                         
*     ****************************************************************  *;

drop JH conb conse a top bottom;

*     ****************************************************************  *;
*       xtpcse - lagged dependent variable, established democracies     *;
*     ****************************************************************  *;

xtpcse enep1 proximity1 enpres  proximity1_enpres eneg logmag logmag_eneg enep1_lag uppertier uppertier_eneg if old==1, pairwise;

generate JH=((_n-1)/10);

replace JH=. if _n>60;

matrix b=e(b); 
matrix V=e(V); 
scalar b1=b[1,1]; 
scalar b2=b[1,2];
scalar b3=b[1,3];

scalar varb1=V[1,1]; 
scalar varb2=V[2,2]; 
scalar varb3=V[3,3];
scalar covb1b3=V[1,3]; 
scalar covb2b3=V[2,3];
set more off;

*     ****************************************************************  *;
*         Create full range of marginal effect                          *;
*     ****************************************************************  *;

gen conb=b1+b3*JH if _n<60;
set more off;

*     ****************************************************************  *;
*           Create full range of standard errors                        *;
*     ****************************************************************  *;

gen conse=sqrt(varb1+varb3*JH^2+2*covb1b3*JH)  if _n<60; 
set more off;

*     ****************************************************************  *;
*               Generate confidence intervals at the 95% level          *;
*     ****************************************************************  *;

gen a=1.645*conse; 
gen top=conb+a; 
gen bottom=conb-a;
set textsize 100;

graph twoway  line conb JH, clwidth(medium) clcolor(blue) clcolor(black)
        ||  line top  JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  line bottom JH, clpattern(dash) clwidth(thin) clcolor(black)
        ||  ,   
            xlabel(0 1 2 3 4 5 6, labsize(2.5)) 
            ylabel(-2 -1 0 1 2 3, labsize(2.5))
            yscale(noline)
            xscale(noline)
            legend(col(1) order(1 2) label(1 "Marginal Effect of Temporally-Proximate Presidential Elections") label(2 "95% Confidence Interval") 
                  label(3 " "))
        yline(0, lcolor(black)) yline(-5 5 -10 -15, lcolor(white))  
            title("Marginal Effect of Temporally-Proximate Presidential Elections", size(4))
            subtitle(" " "Dependent Variable: Effective Number of Electoral Parties" " ", size(3))
            xtitle(Effective Number of Presidential Candidates, size(3)  )
        xsca(titlegap(2))
        ysca(titlegap(2))
            ytitle("Marginal Effect of Temporally-Proximate" "Presidential Elections", size(3))
        scheme(s2mono) graphregion(fcolor(white)); 
                   
*graph export  h:\Dissertation\parties\cps\xtpcse_lag_established.eps, replace;

*     ****************************************************************  *;
*       Conclusion:                                                     *;
*       At 95% significance we have:                                    *;
*       Temporally-proximate presidential elections reduce the number   *;
*       of electoral parties when the number of presidential candidates *;
*       is between 0.5 and 2.8.  They have no effect when presidential  *;
*       candidates are greater than 2.8.                                *;
*       At 90% significance we have:                                    *;
*       Temporally-proximate presidential elections reduce the number   *;
*       of electoral parties when the number of presidential candidates *;
*       is less than 3.1.  They have no effect when presidential        *;
*       candidates are greater than 3.1.                                *;                         
*     ****************************************************************  *;


*     ****************************************************************  *;
*                                   THE END                             *;
*     ****************************************************************  *;


exit;
